package redis

import (
	"context"
	"mpps/tools/config"
	"time"

	"github.com/asim/go-micro/v3/logger"
	"github.com/go-redis/redis/v8"
)

var (
	rdb *redis.Client
)

func init() {
	rdb = redis.NewClient(&redis.Options{
		Addr:     config.G_redisaddr,
		Password: config.G_redispwd,
		DB:       0,
		PoolSize: 100,
	})

	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()

	_, err := rdb.Ping(ctx).Result()
	if err != nil {
		logger.Fatal(err)
		panic(err)
	}
}

func GetRedis() *redis.Client {
	return rdb
}
